<?PHP
/*  stu_fitness_ques  v0.1
 *  Plugin FOR Discuz! X 
 *	By STU Michael && NULL
 */
 
 
 if(!defined('IN_DISCUZ')){
 	exit('Access Denied');
 }

 include_once DISCUZ_ROOT.'./source/function/function_discuzcode.php';
 	//submitcheck 判断是否是远程提交
 	$questionnaireInfo = array();
	
 	if(!submitcheck('newquessubmit')){
 		//echo "helloworld";
 		if(empty($_G['uid'])) showmessage('请先登录再填写问卷' , 'plugin.php?id=stu_fitness:stu_fitness' ,'',array('alert' => 'error'));
	    $mischecktm = "请检查基本信息填写是否完整，没有填写名称的项目将被过滤。确认提交？";
		//問卷id
 		if (!$qid) {
 			showmessage('問卷不存在' , 'plugin.php?id=stu_fitness:stu_fitness' ,'',array('alert' => 'error'));
		}
		//問卷信息
		 $questionnaireInfo 			= DB::fetch_first("SELECT * FROM ".DB::table('fitness_questionnaire')." WHERE `id`='$qid'");
		 
		 if(empty($questionnaireInfo)){
			 	showmessage('您查看的问卷不存在' , 'plugin.php?id=stu_fitness:stu_fitness' ,'',array('alert' => 'error'));
		 }
		 
		 $questionnaireInfo['PostT']	= gmdate("Y-M-D H:i:s",$questionnaireInfo['post_time']); 
		 $questionnaireInfo['EndT']		= gmdate("Y-M-D H:i:s",$questionnaireInfo['deadline']-$questionnaireInfo['post_time']); 
		 
			 	//問題信息列表
			 $questionInfoList	= DB::fetch_all("SELECT * FROM ".DB::table('fitness_question')." WHERE `questionnaire_id`='$qid'");
			 //把問題選項放到問題信息列表中
			 foreach ($questionInfoList as $key => $value) {
				//選項列表
				 $questionInfoList[$key]['options']		= DB::fetch(DB::query("SELECT * FROM ".DB::table('fitness_option')." WHERE `question_id`='$qid'"));
				 
				 switch ($questionInfoList[$key]['question_type']) {
					 case 1:
						 $questionInfoList[$key]['typeInfo'] = "普通单选";
						 break;
					 case 2:
						 $questionInfoList[$key]['typeInfo'] = "普通多选";
						 break;
					 case 3:
						 $questionInfoList[$key]['typeInfo'] = "纯字符填空";
						 break;
					 case 4:
						 $questionInfoList[$key]['typeInfo'] = "学校";
						 break;
					 case 5:
						 $questionInfoList[$key]['typeInfo'] = "省份";
						 break;
					 case 6:
						 $questionInfoList[$key]['typeInfo'] = "日期";
						 break;
					 case 7:
						 $questionInfoList[$key]['typeInfo'] = "数字填空";
						 break;
					 default:
						 
						 break;
				 }
				switch ($questionInfoList[$key]['required']) {
					 case 0:
						 $questionInfoList[$key]['typeInfo']	= "[".$questionInfoList[$key]['typeInfo']."/必做]";
						 break;
					 case 1:
						 $questionInfoList[$key]['typeInfo']	= "[".$questionInfoList[$key]['typeInfo']."/選做]";
						 break;
					 default:
						 
						 break;
				}
				//echo $questionInfoList[$key]['typeInfo'];
			}
		 
 	}else{
 		
 	}
	
 	include template('stu_fitness:fitness_viewques');